//
//  PeiTaoXVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/17.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "PeiTaoXVC.h"


#import "DouSecondCell.h"
#import "DouDetailsCell.h"
#import "TodoHttpManager.h"

@interface PeiTaoXVC ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_titleArr;
    NSMutableDictionary *_dataDic;
    
    
    NSString *str;
    NSString *str1;
    NSString *str2;
    NSString *str3;
    NSString *str4;
    NSString *str5;
    NSString *str6;
    NSString *str7;
    NSString *str8;
    NSString *str9;
    NSString *str10;
    NSString *str11;
    NSString *str12;
    NSString *str13;
    NSString *str14;
    
    NSString *str15;
    NSString *str16;
    NSString *str17;
    NSString *str18;
    NSString *str19;
   
 
    
    NSString *strNum;

}

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *daArr;

@end

@implementation PeiTaoXVC

-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDPeiRenGouX:) name:TDPeiRenGouX object:nil];
    [_manager userGMPeiRenGouXWithID:_imID];
}

-(void)didTDPeiRenGouX:(NSNotification *)notid
{
    
    if (notid.object != nil)
    {
        int status = [[notid.object objectForKey:@"status"] intValue];
        if (status == 1)
        {
            _dataDic = [notid.object objectForKey:@"data"];
            
            str = [_dataDic objectForKey:@"rengou_name"];
            strNum =  [_dataDic objectForKey:@"rengou_phone"];
            str1 = [_dataDic objectForKey:@"id_card"];
            str2 = [_dataDic objectForKey:@"id_card_dz"];
            str3 =  [_dataDic objectForKey:@"rengou_time"];
            str4 = [_dataDic objectForKey:@"fy_name"];
            str5 =  [_dataDic objectForKey:@"dingjin"];
           // str6 = [_dataDic objectForKey:@"sale_area"];
            str7 =  [_dataDic objectForKey:@"sale_price"];
            str8 = [_dataDic objectForKey:@"wylx"];
            str9 =  [_dataDic objectForKey:@"acyh"];
            str10 = [_dataDic objectForKey:@"xieyi_price_all"];
            str11 = [_dataDic objectForKey:@"tbyh"];
            str12 = [_dataDic objectForKey:@"hetong_price_all"];
            str13 = [_dataDic objectForKey:@"pay_way"];
            str14 =  [_dataDic objectForKey:@"should_pay_money"];
            
            str15 = [_dataDic objectForKey:@"true_pay_money"];
            str16 = [_dataDic objectForKey:@"owe_money"];
            str17 = [_dataDic objectForKey:@"sf_status"];
            str18 = [_dataDic objectForKey:@"ptf_status"];
            str19 = [_dataDic objectForKey:@"adviser"];
      
   
            NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
            if ([IDA isEqualToString: @"1"])
            {
                _daArr = [[NSMutableArray alloc] initWithObjects:str,strNum,str1,str2,str3,str4,str5,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str17,str18, nil];
                
            }
            else
            {
                _daArr = [[NSMutableArray alloc] initWithObjects:str,strNum,str1,str2,str3,str4,str5,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str17,str18,str19, nil];
                
            }
            
            
            
           // NSLog(@"1111------%lu",(unsigned long)_daArr.count);
            
            [_tableView reloadData];
        }
        else
        {
            [_manager MakeMyselfAlert:@"获取失败" andIsNeedTitle:NO andShowTime:2.0];
        }
    }
    
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDPeiRenGouX object:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
   self.title = @"我的认购";
    _manager = [TodoHttpManager sharedManager];
    
    _daArr = [NSMutableArray arrayWithCapacity:0];
    _dataDic = [[NSMutableDictionary alloc] init];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 44;
    
    //self.tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    
    NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
    if ([IDA isEqualToString: @"1"])
    {
        _titleArr = [NSArray arrayWithObjects:@"认购姓名 :",@"联系电话 :",@"身份证号 :",@"身份证地址:",@"认购日期 :",@"认购房源 :",@"物业类型 :",@"销售总价 :",@"缴纳定金 :",@"付款方式 :",@"案场优惠 :",@"协议总价 :",@"特别优惠 :", @"合同总价 :",@"应交房款 :",@"是交房款 :",@"总欠房款 :",@"房款状态",@"代收费用状态 :", nil];
    }
    else
    {
        _titleArr = [NSArray arrayWithObjects:@"认购姓名 :",@"联系电话 :",@"身份证号 :",@"身份证地址:",@"认购日期 :",@"认购房源 :",@"物业类型 :",@"销售总价 :",@"缴纳定金 :",@"付款方式 :",@"案场优惠 :",@"协议总价 :",@"特别优惠 :", @"合同总价 :",@"应交房款 :",@"是交房款 :",@"总欠房款 :",@"房款状态",@"代收费用状态 :",@"置业顾问 :", nil];
    }
    

    
    

    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
  //  NSLog(@"222222------%lu",(unsigned long)_titleArr.count);
    return _titleArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        
        NSString *str0 = (NSString *)_daArr[indexPath.row];
        
        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};  //指定字号
        CGRect rect = [str0 boundingRectWithSize:CGSizeMake(LL_ScreenWidth - 117 - 15, MAXFLOAT)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                       NSStringDrawingUsesFontLeading attributes:dic context:nil];
        return rect.size.height+24>44?rect.size.height+24:44;
    }
    return 44;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *cellIndent = @"";
    if (indexPath.row == 1)
    {
        cellIndent = @"CellA";
        DouSecondCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
            
            strNum =  [_dataDic objectForKey:@"rengou_phone"];
            cell.secondLab.text = [NSString stringWithFormat:@"%@",strNum];
            
            [cell setUpUIPbone:[_dataDic objectForKey:@"rengou_phone"]];
            
        }
        
        cell.firstLab.text= @"联系电话:";
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;
        
    }
    else
    {
        cellIndent = @"CellB";
        DouDetailsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
            
            
        }
        if ([cell isKindOfClass:[DouDetailsCell class]])
        {
            if (_daArr.count != 0)
            {
                
                NSString *str0 = (NSString *)_daArr[indexPath.row];
                if (indexPath.row == 3) {
                    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};  //指定字号
                    CGRect rect = [str0 boundingRectWithSize:CGSizeMake(LL_ScreenWidth - 117 - 15, MAXFLOAT)/*计算宽度时要确定高度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
                    cell.rightHeight = rect.size.height + 9*2;
                    cell.rightStr = [NSString stringWithFormat:@"%@",str0];
                }else {
                    cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
                }
               
            }
            
        }
        
        cell.firstLab.text = _titleArr[indexPath.row];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;
        
    }
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
